﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using AccountHelper;

namespace AccountManager
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // first
            if (!IsPostBack)
            {
                textBox_Result.Text = string.Empty;
            }

            // postback
            if (IsPostBack)
            {
            }

            // common
            {
            }
        }

        protected void button_Change_Click(object sender, EventArgs e)
        {
            try
            {
                string ad_domain = ConfigurationManager.AppSettings["AD_DOMAIN"];
                string ad_account = ConfigurationManager.AppSettings["AD_ACCOUNT"];
                string ad_password = ConfigurationManager.AppSettings["AD_PASSWORD"];

                AccountSetter.ChangePassword(ad_domain, ad_account, ad_password, textBox_account.Text, textBox_password.Text, textBox_password_new.Text);

                textBox_Result.Text = "비밀번호 변경 완료" + Environment.NewLine + DateTime.Now.ToString("yyyy년 MM월 dd일  HH시 mm분 ss초");
            }
            catch (Exception ex)
            {
                textBox_Result.Text = MakeExceptionMessage(ex);
            }
        }

        protected string MakeExceptionMessage(Exception ex)
        {
            return string.Format("[Message]\n{0}\n\n[StackTrace]\n{1}\n", ex.Message, ex.StackTrace);
        }
    }
}
